Xbasic

google_sheet_to_json Function

Syntax

C result = google_sheet_to_json(C spreadsheetId, C range)

Arguments

spreadsheetIdCharacter

The id of the Google Sheet to read.

rangeCharacter

The range of data to read.

The range starts with the sheet name followed by ! and the starting and ending cell address, separated by a colon. For example: Sheet1!A1:E10

Returns

resultCharacter

Returns a JSON string containing the data read from the sheet.

If spreadsheetId is blank, the function returns the service account email address that the sheet must be shared with.

Description

Reads data from a Google Sheet and returns the data as a JSON string.

Important

Before you can use this function with your Google Sheet, you must first share the sheet with this email address:

sheets@sheets-448303.iam.gserviceaccount.com

You can get this email address by calling google_sheet_to_json() with a blank id. For example:

google_sheet_to_json("","")

Spreadsheet Id

The Sheet id is obtained by taking the address shown in the browser when you have the sheet open and then extracting the id from the URL:

https://docs.google.com/spreadsheets/d/this_is_the_id/edit?gid=0#gid=0

Example

dim id as c = "1klxbQOgMiE1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
dim range as c = "Sheet1!A1:B5"

? google_sheet_to_json(id,range)

See Also